<?php

// +----------------------------------------------------------------------

// | Description: 客户

// +----------------------------------------------------------------------

// | Author: zl

// +----------------------------------------------------------------------



namespace app\crm\controller;



use app\admin\controller\ApiCommon;

use app\crm\model\Customer as CustomerModel;
use app\crm\model\CustomerConfig as CustomerConfigModel;
use app\crm\model\StaffModel;

use think\response\Json;

use think\facade\Db;

use think\facade\Request;

class Staff extends ApiCommon

{
    
    protected $customerModel;

    protected $customerConfigModel;

    /**

     * 用于判断权限

     * @permission 无限制

     * @allow 登录用户可访问

     * @other 其他根据系统设置

     **/

    public function initialize()

    {

        $action = [

            'permission' => ['add_question'],

            'allow' => ['users', 'info']

        ];

        event('CheckAuth',$action);

        $request = $this->request;

        $a = strtolower($request->action());



        $this->customerModel = new CustomerModel();

        $this->customerConfigModel = new CustomerConfigModel();

        if (!in_array($a, $action['permission'])) {

            parent::initialize();

        }

    }
    
    public function staffBaoyou(){

        $request = $this->param;

        $model = new StaffModel();

        $data = $model->getStaffBaoyou($request);

        $export = $request['export'] ?? '';

        if($export){

            $callName = [

                'name'   =>'姓名',
    
                'sex' =>'门店',
    
                'marketName' =>'市场',
    
                'shopName' =>'门店',
    
                'positionName' =>'职位',
    
                'cj_customer'     =>'成交顾客数',
    
                'baoyou_customer'    =>'保有顾客数',
    
                'lost_customer'   =>'流失顾客数',
    
                'warn_customer'    =>'流失预警数',
    
                'baoyou_rate'    =>'保有率',
    
    
            ];


            $timeStr = date('Y-m-d',time());

            $downUrl = exportExcelData('员工保有率',$callName,$data,'xlsx',1);

            return resultArray(['data' =>['url' => 'http://'.$_SERVER['HTTP_HOST'].$downUrl],'error' => '获取成功']);
            
            exit;
        }

        return resultArray(['data' => $data]);
    }

}